using System;
using System.Windows.Forms;

namespace roster.UI
{
    public static class ObjectCollectionExtension
    {
        public static T Find<T>(this ListBox.ObjectCollection collection, Func<T, bool> matches) 
        {
            foreach (var obj in collection)
            {
                if(matches((T) obj))
                {
                    return (T) obj;
                }
            }

            throw new ArgumentException("Mo matches found in collection.");
        }
    }
}